//
//  NSURLRequest+RequestData.m
//  Arts1
//
//  Created by apple on 15/10/8.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "NSURLRequest+RequestData.h"
#import "AllHeader.h"



@implementation NSURLRequest (RequestData)


//无参数的网络数据请求
+ (void)requestDataWithURL:(NSString *)URL
{
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataForKeyAndUid"];
    
    NSString *uid = dic[@"data"][@"uid"];
    
    NSString *key = dic[@"data"][@"key"];
    
    NSDictionary *pardic = [NSDictionary dictionary];
    
    if (uid && key)
    {
        pardic = @{@"uid":uid,
                   @"key":key};
    }
    
    [manage POST:URL parameters:pardic
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
             
             // 请求成功的时候调用这个block
             NSLog(@"数据请求--%@", data);
         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             // 请求失败的时候调用调用这个block
             NSLog(@"请求失败");
         }];
}

@end
